package com.zmn.oms.business.impl.attachment;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zmn.account.common.utils.NumberUtil;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.common.utils.reflect.BeanMapper;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.consts.GlobalConsts;
import com.zmn.manager.redis.lock.DistributedLock;
import com.zmn.manager.redis.lock.DistributedLockUtils;
import com.zmn.oms.business.interfaces.attachment.AttachmentBService;
import com.zmn.oms.business.interfaces.conf.attachment.ConfOrderAttachmentBService;
import com.zmn.oms.business.interfaces.masterphoto.OrderPhotoBService;
import com.zmn.oms.business.interfaces.yeyxplus.YeyxPlusBService;
import com.zmn.oms.common.annotation.ZsNormalOrderWorkLog;
import com.zmn.oms.common.constant.*;
import com.zmn.oms.common.dro.attachment.AttachmentDetailDRO;
import com.zmn.oms.common.dro.attachment.AttachmentDetailGroupDRO;
import com.zmn.oms.common.dro.attachment.WorkAttachmentDRO;
import com.zmn.oms.common.dro.work.attachment.OrderWorkAttachmentDetailDRO;
import com.zmn.oms.common.exception.OmsBaseException;
import com.zmn.oms.model.dto.orderattachment.ModifyOrderAttachmentDTO;
import com.zmn.oms.model.entity.conf.attachment.ConfOrderAttachment;
import com.zmn.oms.model.entity.conf.attachment.ConfOrderAttachmentCategory;
import com.zmn.oms.model.entity.conf.attachment.ConfOrderAttachmentCategoryQuery;
import com.zmn.oms.model.entity.order.OrderExtend;
import com.zmn.oms.model.entity.orderattachment.OrderAttachment;
import com.zmn.oms.model.entity.orderattachment.OrderAttachmentQuery;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.model.vo.attachment.AttachmentDetailGroupVO;
import com.zmn.oms.model.vo.attachment.AttachmentDetailVO;
import com.zmn.oms.services.interfaces.conf.attachment.ConfOrderAttachmentCategoryService;
import com.zmn.oms.services.interfaces.order.OrderExtendService;
import com.zmn.oms.services.interfaces.orderattachment.OrderAttachmentService;
import com.zmn.oms.services.interfaces.work.OrderWorkService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;


/**
 * 类描述：工单附件 - 逻辑处理类
 *
 * @author liudi
 * @since: 2022/3/30 17:43
 */
@Slf4j
@Service
public class AttachmentBServiceImpl implements AttachmentBService {

	@Resource
	private OrderAttachmentService orderAttachmentService;
	@Resource
	private OrderPhotoBService orderPhotoBService;
	@Resource
	private OrderWorkService orderWorkService;
	@Resource
	private ConfOrderAttachmentCategoryService confOrderAttachmentCategoryService;
	@Resource
	private ConfOrderAttachmentBService confOrderAttachmentBService;
	@Resource
	private OrderExtendService orderExtendService;
	@Autowired
	private YeyxPlusBService yeyxPlusBService;

	@NacosValue(value = "${app.h5.attachment.appEgUrl:https://test2-h5-mapp.xiujiadian.com/product?confAttachmentId=%s}", autoRefreshed = true)
	private String appEgUrl;

	/**
	 * 运营后台获取附件信息
	 *
	 * @param orderWork
	 * @return
	 */
	@Override
	public List<AttachmentDetailGroupVO> getOrderAttachmentByOrderWork(OrderWork orderWork) {

		// 查询附件
		List<OrderAttachment> attachmentList = orderAttachmentService.listAttachmentByOrderId(orderWork.getOrderId());
		if (CollectionUtils.isEmpty(attachmentList)) {
			return Lists.newArrayList();
		}

		// 根据照片类型分组
		Map<Integer, List<OrderAttachment>> attachmentMap = attachmentList.stream().collect(Collectors.groupingBy(OrderAttachment::getType));

		// 查询所有类型
		List<ConfOrderAttachmentCategory> confOrderAttachmentCategories = confOrderAttachmentCategoryService.listByQuery(new ConfOrderAttachmentCategoryQuery());
		Map<Integer, ConfOrderAttachmentCategory> categoryMap = confOrderAttachmentCategories.stream().
				collect(Collectors.toMap(item -> item.getCategId(), item -> item, (p, u) -> p));

		// 组装查询条件
		OrderAttachmentQuery orderAttachmentQuery = new OrderAttachmentQuery();
		orderAttachmentQuery.setOrderId(orderWork.getOrderId());
		orderAttachmentQuery.setWorkId(orderWork.getWorkId());
		orderAttachmentQuery.setBizType(orderWork.getBizType());
		orderAttachmentQuery.setChannelId(orderWork.getChannelId());
		orderAttachmentQuery.setServCategId(orderWork.getServCategId());

		// 查询照片配置
		List<ConfOrderAttachment> pictureConfigList = confOrderAttachmentBService.listConfigOrderPictureAttachmentByQuery(orderAttachmentQuery);
		Map<Integer, ConfOrderAttachment> pictureConfigMap = pictureConfigList.stream().collect(Collectors.toMap(item -> item.getCategId(), item -> item, (p, u) -> p));

		// 分组展示
		List<AttachmentDetailGroupVO> detailGroupVOList = Lists.newArrayListWithExpectedSize(attachmentMap.size());
		attachmentMap.keySet().forEach(type -> {
			List<OrderAttachment> orderAttachmentList = attachmentMap.get(type);
			if (CollectionUtils.isEmpty(orderAttachmentList)) {
				return;
			}

			ConfOrderAttachment confOrderAttachment = Optional.ofNullable(pictureConfigMap.get(type)).orElse(new ConfOrderAttachment());
			ConfOrderAttachmentCategory confOrderAttachmentCategory = Optional.ofNullable(categoryMap.get(type)).orElse(new ConfOrderAttachmentCategory());

			// 视频不审核
			if (OrderAttachmentCategoryTypeEnum.VIDEO.getCode().equals(confOrderAttachmentCategory.getType())) {
				return;
			}

			OrderAttachment firstAttachment = orderAttachmentList.get(0);
			// 如果附件的 src 有, 就只查看第一个src。
			if (firstAttachment.getSrcIndex() == null && firstAttachment.getSrc().contains(",")) {
				String firstSrc = firstAttachment.getSrc().split(",")[0];
				firstAttachment.setSrc(firstSrc);
			}

			AttachmentDetailGroupVO attachmentDetailGroupVO = new AttachmentDetailGroupVO();
			attachmentDetailGroupVO.setType(type);
			attachmentDetailGroupVO.setTypeName(confOrderAttachmentCategory.getCategName());
			attachmentDetailGroupVO.setEgSrc(confOrderAttachment.getEgSrc());
			attachmentDetailGroupVO.setDescription(confOrderAttachment.getDescription());
			attachmentDetailGroupVO.setAttachmentDetailVOList(BeanMapper.mapList(orderAttachmentList, AttachmentDetailVO.class));

			detailGroupVOList.add(attachmentDetailGroupVO);
		});

		return detailGroupVOList;
	}

	/**
	 * 获取工单附件
	 *
	 * @param orderAttachmentQuery
	 * @return
	 */
	@Override
	public WorkAttachmentDRO getOrderAttachmentAndConfigByQuery(OrderAttachmentQuery orderAttachmentQuery) throws OmsBaseException {
		Objects.requireNonNull(orderAttachmentQuery);
		Objects.requireNonNull(orderAttachmentQuery.getOrderId());

		OrderWork orderWork = orderWorkService.findOrderWorkByKey(orderAttachmentQuery.getOrderId(), orderAttachmentQuery.getWorkId());
		log.info("照片配置查询出的工单:{}",orderWork);
		// 兼容没有传服务分类或业务线
		if (Objects.isNull(orderAttachmentQuery.getServCategId()) || Objects.isNull(orderAttachmentQuery.getBizLine())) {
			orderAttachmentQuery.setBizType(orderWork.getBizType());
			orderAttachmentQuery.setChannelId(orderWork.getChannelId());
			orderAttachmentQuery.setProductId(orderWork.getShowProductId());
			orderAttachmentQuery.setCityId(orderWork.getCityId());
			orderAttachmentQuery.setServCategId(orderWork.getServCategId());
			orderAttachmentQuery.setBizLine(orderWork.getBizLine());
		}

		List<OrderAttachment> orderAttachmentList = orderAttachmentService.listAttachmentByOrderId(orderAttachmentQuery.getOrderId());

		// 拆分照片附件
		orderAttachmentList = this.splitAttachmentSrc(orderAttachmentQuery.getOrderId(), orderAttachmentList);

		// 根据照片类型分组 key：分类ID value：【照片/视频】附件对象
		Map<Integer, List<OrderAttachment>> attachmentMap = orderAttachmentList.stream().collect(Collectors.groupingBy(OrderAttachment::getType));

		WorkAttachmentDRO workAttachmentDRO = new WorkAttachmentDRO();
		// 获取照片 与 视频附件
		workAttachmentDRO.setPictureList(this.listOrderPictureAttachment(orderAttachmentQuery, attachmentMap));
		workAttachmentDRO.setServiceVideoList(this.listOrderVideoAttachment(orderAttachmentQuery, attachmentMap));

		// 言而有信不处理贴画照
		boolean isYeyx = yeyxPlusBService.isYeyxPilot(orderWork.getCompanyId(), orderWork.getCityId(), orderWork.getMasterId());
		if (isYeyx) {
			workAttachmentDRO.setPictureList(workAttachmentDRO.getPictureList().stream().filter(e -> !Objects.equals(e.getType(), OrderAttachmentTypeEnum.THZ.getCode())).collect(Collectors.toList()));
		}

		return workAttachmentDRO;
	}

	/**
	 * 拆分照片附件：
	 * 订单对应的某个照片类型的附件如果【数量是1，并且src有“,”】时，则拆分。
	 *
	 * @param orderAttachmentList
	 * @return
	 * @author liudi
	 * @since: 2022/3/25 18:35
	 */
	@Transactional(rollbackFor = Exception.class)
	public List<OrderAttachment> splitAttachmentSrc(Long workId, List<OrderAttachment> orderAttachmentList) throws OmsBaseException {
		// 锁超时时间：15秒
		DistributedLock lock = DistributedLockUtils.build(String.format(LockConsts.LOCK_ORDER_ATTACHMENT, workId), LockConsts.LOCK_VALID_TIME);
		if (!lock.tryLock()) {
			return orderAttachmentList;
		}

		try {
			// 获取需要拆分【src】的数据
			List<OrderAttachment> needSplitAttachmentList = orderAttachmentList
					.stream()
					.filter(item -> item.getSrcIndex() == null && item.getSrc().contains(","))
					.collect(Collectors.toList());

			if (CollectionUtils.isEmpty(needSplitAttachmentList)) {
				return orderAttachmentList;
			}

			Date now = DateUtil.getNow();
			ArrayList<Long> deleteIds = Lists.newArrayList();
			ArrayList<OrderAttachment> insertAttachmentList = Lists.newArrayList();

			for (OrderAttachment needSplitAttachment : needSplitAttachmentList) {
				String[] imageSrcArray = needSplitAttachment.getSrc().split(",");

				for (int i = 0; i < imageSrcArray.length; i++) {
					OrderAttachment attachment = BeanMapper.map(needSplitAttachment, OrderAttachment.class);
					attachment.setSrc(imageSrcArray[i]);
					attachment.setSrcIndex(i);
					attachment.setUpdateTime(now);
					insertAttachmentList.add(attachment);
				}

				deleteIds.add(needSplitAttachment.getAttachmentId());
			}
			orderAttachmentService.insertAttachmentList(insertAttachmentList);

			// 删除【拆分前】的附件数据
			orderAttachmentService.deleteBatchByAttachmentIds(deleteIds);

			List<OrderAttachment> attachmentList = orderAttachmentList.stream().filter(item -> !deleteIds.contains(item.getAttachmentId())).collect(Collectors.toList());
			attachmentList.addAll(insertAttachmentList);
			return attachmentList;

		} catch (Exception e) {
			e.printStackTrace();
			log.error("拆分照片数据发生异常：{}", e.getMessage());
			throw new OmsBaseException(String.format("拆分照片数据发生异常：%s", e.getMessage()));
		} finally {
			// 释放锁
			lock.unlock();
		}
	}

	@Override
	@ZsNormalOrderWorkLog(type = OrderLogConsts.ORDER_LOG_TYPE_ATTACHMENT_IMAGE, beforeProceed = false)
	public void modifyOrderWorkAttachment(ModifyOrderAttachmentDTO modifyOrderAttachmentDTO) throws OmsBaseException {
		Objects.requireNonNull(modifyOrderAttachmentDTO.getOrderId(), "订单ID不能为空");
		Objects.requireNonNull(modifyOrderAttachmentDTO.getType(), "附件类型不能为空");

		OrderAttachment awaitOperateAttachment;
		OrderWork orderWork = orderWorkService.findOrderWorkByKey(modifyOrderAttachmentDTO.getOrderId(), modifyOrderAttachmentDTO.getWorkId());

		if (Objects.isNull(orderWork)) {
			log.error("工单不存在");
			return;
		}

		if (StringUtil.isBlank(modifyOrderAttachmentDTO.getSrc())) {
			log.error("照片Src不能为null，orderId:{}", modifyOrderAttachmentDTO.getOrderId());
			return;
		}

		// 是否需要自动审核
		Boolean needReview = false;

		// 新增操作
		if (NumberUtil.isNullOrZero(modifyOrderAttachmentDTO.getAttachmentId())) {
			// 组装查询对象
			OrderAttachmentQuery orderAttachmentQuery = OrderAttachmentQuery.builder()
					.orderId(orderWork.getOrderId())
					.workId(orderWork.getWorkId())
					.type(modifyOrderAttachmentDTO.getType())
					.bizType(orderWork.getBizType())
					.channelId(orderWork.getChannelId())
					.servCategId(orderWork.getServCategId()).build();

			// 查询某个类型的照片配置
			ConfOrderAttachment attachmentConfig = confOrderAttachmentBService.getAttachmentConfigByQuery(orderAttachmentQuery);
			if (attachmentConfig == null) {
				log.info("订单号：[{}] 未查询出[type:{}]的附件配置。", orderWork.getOrderId(), modifyOrderAttachmentDTO.getType());
			}

			awaitOperateAttachment = BeanMapper.map(modifyOrderAttachmentDTO, OrderAttachment.class);
			awaitOperateAttachment.setCreater(modifyOrderAttachmentDTO.getOperator());
			awaitOperateAttachment.setUpdater(modifyOrderAttachmentDTO.getOperator());

			needReview = Objects.nonNull(attachmentConfig) && Objects.equals(attachmentConfig.getNeedReview(), GlobalConsts.YES);
			if (needReview) {
				awaitOperateAttachment.setNeedReview(attachmentConfig.getNeedReview());
				awaitOperateAttachment.setReviewStatus(OrderConsts.IMAGE_REVIEW_STATUS_WAITING);
			} else {
				awaitOperateAttachment.setNeedReview(GlobalConsts.NO);
				awaitOperateAttachment.setReviewStatus(OrderConsts.IMAGE_REVIEW_STATUS_NO);
			}

			orderAttachmentService.insertAttachment(awaitOperateAttachment);
			log.info("照片附件操作 - 新增：{}", awaitOperateAttachment);

		} else {
			awaitOperateAttachment = orderAttachmentService.findAttachmentByKey(modifyOrderAttachmentDTO.getAttachmentId());

			if (Objects.isNull(awaitOperateAttachment)) {
				log.info("待操作的【附件对象】不存在。入参：[{}]", modifyOrderAttachmentDTO);
				return;
			}

			if (Objects.equals(modifyOrderAttachmentDTO.getOpType(), OrderConsts.ORDER_IMAGE_DELETE)) {
				// 删除操作
				orderAttachmentService.deleteByKey(awaitOperateAttachment.getAttachmentId());
				log.info("照片附件操作-删除：{}", awaitOperateAttachment);
			} else {
				// 更新操作
				awaitOperateAttachment.setSrc(modifyOrderAttachmentDTO.getSrc());

				// 如果是无需审核，不用改审核状态，其他的状态改为待审核
				if (!Objects.equals(awaitOperateAttachment.getReviewStatus(), OrderConsts.IMAGE_REVIEW_STATUS_NO)) {
					awaitOperateAttachment.setReviewStatus(OrderConsts.IMAGE_REVIEW_STATUS_WAITING);
				}
				orderAttachmentService.updateAttachmentSrcByKey(awaitOperateAttachment);
				log.info("照片附件操作-修改：{}", awaitOperateAttachment);

				// 是否需要自动审核
				needReview = Objects.equals(awaitOperateAttachment.getNeedReview(), GlobalConsts.YES);
			}
		}

		// 如果是贴花照，既保存到附件表中，也保存到扩展表中。
		if (Objects.equals(awaitOperateAttachment.getType(), OrderAttachmentTypeEnum.CONSTS_THZ)) {
			OrderExtend orderExtend = new OrderExtend();
			orderExtend.setExtId(awaitOperateAttachment.getOrderId());
			if (Objects.equals(modifyOrderAttachmentDTO.getOpType(), OrderConsts.ORDER_IMAGE_DELETE)) {
				orderExtend.setAppliqueSrc("");
			} else {
				orderExtend.setAppliqueSrc(awaitOperateAttachment.getSrc());
			}
			orderExtendService.updateOrderExtend(orderExtend);

			// 修改工单的贴花状态
			OrderWork updateOrderWork = new OrderWork();
			updateOrderWork.setOrderId(orderWork.getOrderId());
			updateOrderWork.setWorkId(orderWork.getWorkId());
			if (Objects.equals(modifyOrderAttachmentDTO.getOpType(), OrderConsts.ORDER_IMAGE_DELETE)) {
				updateOrderWork.setAppliqueStatus(0);
			} else {
				updateOrderWork.setAppliqueStatus(awaitOperateAttachment.getReviewStatus());
			}
			orderWorkService.updateOrderWorkByKey(updateOrderWork);

			log.info("照片附件操作-修改贴花照：{}", awaitOperateAttachment);
		}

		// 自动审核
		if (needReview) {
			orderPhotoBService.sendImageDetectionMessage(orderWork.getOrderId(), orderWork.getWorkId(), awaitOperateAttachment.getAttachmentId(),
					awaitOperateAttachment.getType());
		}

	}

	/**
	 * 获取工单照片附件
	 *
	 * @param orderAttachmentQuery
	 * @param attachmentMap
	 * @return
	 */
	private List<AttachmentDetailGroupDRO> listOrderPictureAttachment(OrderAttachmentQuery orderAttachmentQuery,
																	  Map<Integer, List<OrderAttachment>> attachmentMap) {
		// 查询渠道图片配置
		List<ConfOrderAttachment> pictureConfigList = confOrderAttachmentBService.listConfigOrderPictureAttachmentByQuery(orderAttachmentQuery);
		if (CollectionUtils.isEmpty(pictureConfigList)) {
			return Lists.newArrayList();
		}

		Map<Integer, String> categoryNameMap;
		List<Integer> categoryIds = pictureConfigList.stream().map(ConfOrderAttachment::getCategId).collect(Collectors.toList());
		List<ConfOrderAttachmentCategory> categoryList = confOrderAttachmentCategoryService.listByIds(categoryIds);
		if (log.isDebugEnabled()) {
			log.debug("“工单照片” - 获取【照片分类信息】 入参：{} 出参：{}", categoryIds, categoryList);
		}

		if (CollectionUtils.isNotEmpty(categoryList)) {
			categoryNameMap = categoryList.stream().collect(Collectors.toMap(ConfOrderAttachmentCategory::getCategId, ConfOrderAttachmentCategory::getCategName));
		} else {
			categoryNameMap = Maps.newHashMap();
		}

		// 组装VO对象
		List<AttachmentDetailGroupDRO> detailGroupVOList = Lists.newArrayListWithCapacity(pictureConfigList.size());
		pictureConfigList.forEach(pictureConfig -> {
			// 组装【附件组】数据
			AttachmentDetailGroupDRO attachmentDetailGroupDRO = new AttachmentDetailGroupDRO();
			attachmentDetailGroupDRO.setType(pictureConfig.getCategId());
			attachmentDetailGroupDRO.setTypeName(categoryNameMap.get(pictureConfig.getCategId()));
			attachmentDetailGroupDRO.setRequiredFlag(pictureConfig.getMustUpload());
			attachmentDetailGroupDRO.setNumber(pictureConfig.getNum());
			attachmentDetailGroupDRO.setEgSrc(pictureConfig.getEgSrc());
			attachmentDetailGroupDRO.setDescription(pictureConfig.getDescription());
			attachmentDetailGroupDRO.setNeedReview(pictureConfig.getNeedReview());
			attachmentDetailGroupDRO.setAutoAudit(pictureConfig.getAutoAudit());
			attachmentDetailGroupDRO.setRephotograph(pictureConfig.getRephotograph());
			attachmentDetailGroupDRO.setOrderDetailShow(pictureConfig.getOrderDetailShow());

			// 如果有配置【详细说明】则【使用其详细说明】，【无详细说明】 && 类型是【装备照】，则使用兜底的【装备照上传标准地址】
			if (StringUtils.isNotBlank(pictureConfig.getDetailDescription())) {
				attachmentDetailGroupDRO.setEgUrl(String.format(appEgUrl, pictureConfig.getId()));
			} else if (Objects.equals(pictureConfig.getCategId(), OrderAttachmentTypeEnum.CONSTS_ZBZ)) {
				attachmentDetailGroupDRO.setEgUrl(OrderAttachmentConsts.UPLOAD_STANDARD_ZBZ_URL);
			}

			// 组装【每组内】的附件数据
			List<OrderAttachment> orderAttachments = attachmentMap.getOrDefault(pictureConfig.getCategId(), Lists.newArrayList());
			attachmentDetailGroupDRO.setAttachmentDetailVOList(BeanMapper.mapList(orderAttachments, AttachmentDetailDRO.class));
			detailGroupVOList.add(attachmentDetailGroupDRO);
		});

		return detailGroupVOList;
	}


	/**
	 * 获取工单视频附件
	 *
	 * @param orderAttachmentQuery
	 * @param attachmentMap
	 * @return
	 */
	private List<OrderWorkAttachmentDetailDRO> listOrderVideoAttachment(OrderAttachmentQuery orderAttachmentQuery,
																		Map<Integer, List<OrderAttachment>> attachmentMap) {
		// 查询渠道视频配置
		List<ConfOrderAttachment> videoConfigList = confOrderAttachmentBService.listConfigOrderVideoAttachmentByQuery(orderAttachmentQuery);
		if (CollectionUtils.isEmpty(videoConfigList)) {
			return Lists.newArrayList();
		}

		Map<Integer, String> categoryNameMap;
		List<Integer> categoryIds = videoConfigList.stream().map(ConfOrderAttachment::getCategId).collect(Collectors.toList());
		List<ConfOrderAttachmentCategory> categoryList = confOrderAttachmentCategoryService.listByIds(categoryIds);
		if (log.isDebugEnabled()) {
			log.debug("获取工单“视频” - 查询【附件分类】信息 入参：{} 出参：{}", categoryIds, categoryList);
		}

		if (CollectionUtils.isNotEmpty(categoryList)) {
			categoryNameMap = categoryList.stream().collect(Collectors.toMap(ConfOrderAttachmentCategory::getCategId, ConfOrderAttachmentCategory::getCategName));
		} else {
			categoryNameMap = Maps.newHashMap();
		}

		// 获取视频类型的附件
		List<OrderWorkAttachmentDetailDRO> attachmentDetailVOList = Lists.newArrayListWithCapacity(videoConfigList.size());
		videoConfigList.forEach(videoConfig -> {
			List<OrderAttachment> orderAttachments = attachmentMap.getOrDefault(videoConfig.getCategId(), Lists.newArrayList());
			OrderWorkAttachmentDetailDRO orderWorkAttachmentDetailVO = new OrderWorkAttachmentDetailDRO();

			if (CollectionUtils.isNotEmpty(orderAttachments)) {
				OrderAttachment orderAttachment = orderAttachments.get(0);
				BeanMapper.copy(orderAttachment, orderWorkAttachmentDetailVO);
				if (StringUtils.isNotBlank(orderAttachment.getSrc())) {
					orderWorkAttachmentDetailVO.setVideoThumbnailSrc(String.format("%s?x-oss-process=video/snapshot,t_10000,m_fast", orderAttachment.getSrc()));
				}
			}
			orderWorkAttachmentDetailVO.setType(videoConfig.getCategId());
			orderWorkAttachmentDetailVO.setTypeName(categoryNameMap.get(videoConfig.getCategId()));
			orderWorkAttachmentDetailVO.setRequiredFlag(videoConfig.getMustUpload());
			orderWorkAttachmentDetailVO.setNumber(videoConfig.getNum());
			orderWorkAttachmentDetailVO.setAutoAudit(videoConfig.getAutoAudit());
			// 视频链接地址
			orderWorkAttachmentDetailVO.setEgSrc(videoConfig.getEgSrc());
			orderWorkAttachmentDetailVO.setDescription(videoConfig.getDescription());
			if (StringUtils.isNotBlank(videoConfig.getEgSrc())) {
				orderWorkAttachmentDetailVO.setEgVideoThumbnailSrc(String.format("%s?x-oss-process=video/snapshot,t_10000,m_fast", videoConfig.getEgSrc()));
			}

			attachmentDetailVOList.add(orderWorkAttachmentDetailVO);
		});

		return attachmentDetailVOList;
	}

}
